{include file="public/header"/}
<link rel="stylesheet" type="text/css" href="{__PUBLIC_PATH}/common/plugins/codemirror/codemirror.css?t={php}echo time();{/php}">
<script type="text/javascript" src="{__PUBLIC_PATH}/common/plugins/codemirror/codemirror.js?t={php}echo time();{/php}"></script>
<script type="text/javascript" src="{__PUBLIC_PATH}/common/plugins/codemirror/mode/xml/xml.js?t={php}echo time();{/php}"></script>
<script type="text/javascript" src="{__PUBLIC_PATH}/common/plugins/codemirror/mode/javascript/javascript.js?t={php}echo time();{/php}"></script>
<script type="text/javascript" src="{__PUBLIC_PATH}/common/plugins/codemirror/mode/css/css.js?t={php}echo time();{/php}"></script>
<script type="text/javascript" src="{__PUBLIC_PATH}/common/plugins/codemirror/mode/php/php.js?t={php}echo time();{/php}"></script>
<script type="text/javascript" src="{__PUBLIC_PATH}/common/plugins/codemirror/mode/clike/clike.js?t={php}echo time();{/php}"></script>
<script type="text/javascript" src="{__PUBLIC_PATH}/common/plugins/codemirror/mode/htmlmixed/htmlmixed.js?t={php}echo time();{/php}"></script>
</head>
<body>
<div class="layui-form">
<div class="layui-fluid pd83">
<div class="layui-col-sm12">
    <div class="layui-card pcf30">
        <div class="layui-form-item">
            <label class="layui-form-label"><b class="pcfts">*</b>文件路径</label>
            <div class="layui-input-inline">
            <input type="text" name="activepath" value="{$info['activepath']|default=''}" lay-verify="required" class="layui-input">
            </div>
            <div class="layui-input-inline lh38 auto">
              空白表示根目录，不允许用 “..” 形式的路径
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><b class="pcfts">*</b>文件名称</label>
            <div class="layui-input-inline">
            <input type="text" name="filename" value="{$info['filename']|default=''}" lay-verify="required" class="layui-input">
            </div>
            <div class="layui-input-inline lh38 auto">
              不允许用 “..” 形式的路径
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">文件源码</label>
            <div class="layui-form-inline2">
            <textarea id="content" lay-ignore>{$info.content|default=''}</textarea>
            </div>
        </div>
    </div>
</div>
<div class="pcfclear"></div>
</div>
<div class="submit-info text-center">
    <button class="layui-btn" lay-submit lay-filter="formSubmit">确认提交</button>
    <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
</div>
</div>

{include file="public/footer"/}
<script>
  layui.use(['layer', 'form'], function () {
    var $ = layui.$,
    layer = layui.layer,
    form = layui.form;

    var editor = CodeMirror.fromTextArea(document.getElementById('content'), {
        lineNumbers: true, // 显示行号
        lineWrapping: true, // 在行槽中添加行号显示器、折叠器、语法检测器`
        autofocus:true,  //自动聚焦
        mode: '{$info.extension}'
    });

    //监听提交
    form.on('submit(formSubmit)', function(data){
        layer.msg('正在处理请勿刷新页面', {icon: 16,shade: 0.01,time:3600000});
        data.field.content = editor.getValue();
        $.ajax({
            type : 'post',
            url : "{:url('/filemanager/edit')}",
            data : data.field,
            dataType : 'json',
            success : function(res){
                layer.closeAll('loading');
                if(res.status){
                    layer.msg(res.msg,{icon:1,time:1000},function(){
                        parent.location.href = res.url;
                    });
                }else{
                    layer.msg(res.msg,{icon:2,time:1000});
                }
            },
            error: function(e){
                layer.closeAll('loading');
                layer.msg("未知错误，操作中断！", {icon: 2, time: 1000});
            }
        });
        return false;
    });
  });
</script>
</body>
</html>